
const TokenKey = 'authorized-token'

export function getToken() {
  return sessionStorage.getItem(TokenKey)
}

export function setToken(token: string) {
  return sessionStorage.setItem(TokenKey, token)
}

export function removeToken() {
  sessionStorage.removeItem(TokenKey)
}

const LocalLanguageKey = 'local-language'


export function setLocalLanguage(language: string) {
  localStorage.setItem(LocalLanguageKey, language)
}

export function getLocalLanguage(): string {
  if (localStorage.getItem(LocalLanguageKey)) {
    return localStorage.getItem(LocalLanguageKey)!
  } else {
    return "zh"
  }
}

/**
 * 获取url参数方法
 * @param variable
 * @returns
 */
export function getQueryVariable(variable: string): string {
  const query = window.location.search.substring(1);
  const vars = query.split("&");
  for (let i = 0; i < vars.length; i++) {
    const pair = vars[i].split("=");
    if (pair[0] == variable) {
      return pair[1];
    }
  }
  return "";
}
